/*
Copyright 2009 Johan Maasing, Mikael Forsberg

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.google.code.pj2r.resources.mocks.request;

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

public class MockParameterHttpServletRequest extends AbstractMockHttpServletRequest {

	private Hashtable parameters = new Hashtable();

	public void putParameter(String key, String value) {
		List values = (List) parameters.get(key);
		if (values == null) {
			values = new ArrayList();
			parameters.put(key, values);
		}
		values.add(value);
	}

	public MockParameterHttpServletRequest() {
	}

	public String getParameter(String name) {
		List values = (List) parameters.get(name);
		return ((values != null) && (values.size() > 0)) ? (String) values.get(0) : null;
	}

	public Enumeration getParameterNames() {
		return parameters.keys();
	}

	public String[] getParameterValues(String name) {
		List values = (List) parameters.get(name);
		return (values != null) ? (String[]) values.toArray(new String[values.size()])
				: null;
	}

	public Map getParameterMap() {
		return parameters;
	}
}
